package org.kuaishou;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.File;
import java.util.List;

public class Run {
    public static final String USER_DIR = System.getProperty("user.dir");
    public static final String TABLE_NAME = "like_video";

    @Test
    public void loadList() throws Exception {
        String url = "https://www.kuaishou.com/graphql";
        LoadVIdeoList load = new LoadVIdeoList();

        List<String> idList = load.loadList(url, TABLE_NAME, null);
        String join = StringUtils.join(idList, "','");
        String ids = String.format("('%s')", join);
        System.out.println("本次新增:" + idList.size());

        final String find = "SELECT a.* FROM %s A WHERE A.`LOAD_TIME` IS NULL ORDER BY A.SORT DESC ;";
        final String sqlFM = "SELECT a.* FROM %s A \nWHERE A.ID IN %s \nORDER BY A.SORT DESC ";

        String printSQL = "\n" + String.format(find, TABLE_NAME) + "\n\n" + String.format(sqlFM, TABLE_NAME, ids) + "\n";
        System.out.println(printSQL);
        File file = FileUtils.getFile(USER_DIR, "res/SQL.TXT");
        FileUtils.writeStringToFile(file, printSQL, "UTF-8");
    }

    @Test
    public void load() throws Exception {
        String pyVideoRoot = "D:/ROOT/py_video/kuaishou_like";
        LoadVIdeoList load = new LoadVIdeoList();

        load.loadVodeo(TABLE_NAME, pyVideoRoot);
//        load.UPDATE(url, tableName, browserType, pyVideoRoot);
    }


    @Test
    public void updateTable() throws Exception {
        LoadVIdeoList load = new LoadVIdeoList();
        load.updateTable(TABLE_NAME);
    }
}
